{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_jsonl(file):\n",
    "    with open(file, 'r') as f:\n",
    "        return [json.loads(line) for line in f]\n",
    "    \n",
    "    \n",
    "def save_jsonl(data, output_file_path):\n",
    "    with open(output_file_path, 'w') as f:\n",
    "        for item in data:\n",
    "            json.dump(item, f)\n",
    "            f.write('\\n')\n",
    "    print(f\"Saved to {output_file_path}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 选择题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2150\n",
      "4800\n",
      "Saved to /home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/Multichoice.jsonl\n"
     ]
    }
   ],
   "source": [
    "multichoice_p = read_jsonl('/home/ubuntu/hallu_team/RLC-bench/Dataset/bench/Relation/perception/benchmark-3-multichoice.jsonl')\n",
    "multichoice_c = read_jsonl('/home/ubuntu/hallu_team/junkai/Dataset/RLC-bench/bench/Relation/cogintive/benchmark-3-multichoice.jsonl')\n",
    "print(len(multichoice_p))\n",
    "print(len(multichoice_c))\n",
    "for i in range(len(multichoice_p)):\n",
    "    multichoice_p[i]['relation_type'] = 'perception'\n",
    "for i in range(len(multichoice_c)):\n",
    "    multichoice_c[i]['relation_type'] = 'cognitive'\n",
    "a=multichoice_p+multichoice_c\n",
    "save_jsonl(a, '/home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/Multichoice.jsonl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# vqa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "len of perception :2150\n",
      "len of cognitive :2720\n",
      "{'image_id': '713858', 'query_prompt': 'What is the relation with bag and ground in this photo? Please answer in the following format:bag is <relation> ground.', 'label': 'bag is on ground.', 'type': 'VQA', 'mllm_name': '', 'response': '', 'relation_type': 'percetion'}\n",
      "{'image_id': '2336517', 'query_prompt': 'What is the relation with giraffe and plants in this photo? Please answer in the following format:giraffe is <relation> plants.', 'label': 'giraffe is chewing plants.', 'type': 'VQA', 'mllm_name': '', 'response': ''}\n",
      "{'image_id': '713858', 'query_prompt': 'What is the relation with bag and ground in this photo? Please answer in the following format:bag is <relation> ground.', 'label': 'bag is on ground.', 'type': 'VQA', 'mllm_name': '', 'response': '', 'relation_type': 'perception'}\n",
      "{'image_id': '2336517', 'query_prompt': 'What is the relation with giraffe and plants in this photo? Please answer in the following format:giraffe is <relation> plants.', 'label': 'giraffe is chewing plants.', 'type': 'VQA', 'mllm_name': '', 'response': '', 'relation_type': 'cognitive'}\n",
      "Saved to /home/ubuntu/kening/kening/RLC-bench/RLC-bench/Dataset/release_v0/VQA.jsonl\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "vqa_p = read_jsonl('/home/ubuntu/junkai/RLC-bench/bench/Relation/perception/benchmark-3-VQA.jsonl')\n",
    "vqa_c = read_jsonl('/home/ubuntu/junkai/RLC-bench/bench/Relation/cogintive/benchmark-3-VQA.jsonl')\n",
    "print(f'len of perception :{len(vqa_p)}')\n",
    "print(f'len of cognitive :{len(vqa_c)}')\n",
    "print(vqa_p[0])\n",
    "print(vqa_c[0])\n",
    "for i in range(len(vqa_p)):\n",
    "    vqa_p[i]['relation_type'] = 'perception'\n",
    "for i in range(len(vqa_c)):\n",
    "    vqa_c[i]['relation_type'] = 'cognitive'\n",
    "print(vqa_p[0])\n",
    "print(vqa_c[0])\n",
    "a=vqa_p+vqa_c\n",
    "save_jsonl(a, '/home/ubuntu/kening/kening/RLC-bench/RLC-bench/Dataset/release_v0/VQA.jsonl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'image_id': '713858', 'query_prompt': 'What is the relation with bag and ground in this photo? Please answer in the following format:bag is <relation> ground.', 'label': 'bag is on ground.', 'type': 'VQA', 'mllm_name': '', 'response': '', 'relation_type': 'perception'}\n",
      "{'image_id': '2336517', 'query_prompt': 'What is the relation with giraffe and plants in this photo? Please answer in the following format:giraffe is <relation> plants.', 'label': 'giraffe is chewing plants.', 'type': 'VQA', 'mllm_name': '', 'response': '', 'relation_type': 'cognitive'}\n",
      "Saved to /home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/VQA.jsonl\n"
     ]
    }
   ],
   "source": [
    "print(vqa_p[0])\n",
    "print(vqa_c[0])\n",
    "a=multichoice_p+multichoice_c\n",
    "save_jsonl(a, '/home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/VQA.jsonl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 判断题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "len of perception :4300\n",
      "len of cognitive :5440\n",
      "{'image_id': '1592267', 'query_prompt': 'Is the bus driver on bus in this photo? Please answer yes or no.', 'label': 'yes', 'type': 'Yes/No', 'mllm_name': '', 'response': '', 'relation_type': 'percetion'}\n",
      "{'image_id': '2384153', 'query_prompt': 'Is the sheep resting head in this photo? Please answer yes or no.', 'label': 'yes', 'type': 'Yes/No', 'mllm_name': '', 'response': '', 'relation_type': 'percetion'}\n",
      "{'image_id': '1592267', 'query_prompt': 'Is the bus driver on bus in this photo? Please answer yes or no.', 'label': 'yes', 'type': 'Yes/No', 'mllm_name': '', 'response': '', 'relation_type': 'perception'}\n",
      "{'image_id': '2384153', 'query_prompt': 'Is the sheep resting head in this photo? Please answer yes or no.', 'label': 'yes', 'type': 'Yes/No', 'mllm_name': '', 'response': '', 'relation_type': 'cognitive'}\n",
      "Saved to /home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/YESNO.jsonl\n"
     ]
    }
   ],
   "source": [
    "vqa_p = read_jsonl('/home/ubuntu/hallu_team/RLC-bench/Dataset/bench/Relation/perception/benchmark-3-YesandNo.jsonl')\n",
    "vqa_c = read_jsonl('/home/ubuntu/hallu_team/RLC-bench/Dataset/bench/Relation/cogintive/benchmark-3-YesandNo.jsonl')\n",
    "print(f'len of perception :{len(vqa_p)}')\n",
    "print(f'len of cognitive :{len(vqa_c)}')\n",
    "print(vqa_p[0])\n",
    "print(vqa_c[0])\n",
    "for i in range(len(vqa_p)):\n",
    "    vqa_p[i]['relation_type'] = 'perception'\n",
    "for i in range(len(vqa_c)):\n",
    "    vqa_c[i]['relation_type'] = 'cognitive'\n",
    "print(vqa_p[0])\n",
    "print(vqa_c[0])\n",
    "a=vqa_p+vqa_c\n",
    "save_jsonl(a, '/home/ubuntu/hallu_team/RLC-bench/Dataset/release_v0/YESNO.jsonl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9740\n"
     ]
    }
   ],
   "source": [
    "print(len(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llava_cjk",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
